package com.jkgh.remedium.states {
	import com.jkgh.logger.Log;
	import com.jkgh.remedium.RemediumSystem;
	
	public class InitializeSystemState implements RemediumState {

		private var mainObjectReceivingState:RemediumState;
		
		public function InitializeSystemState(mainObjectReceivingState:RemediumState) {
			this.mainObjectReceivingState = mainObjectReceivingState;
		}
		
		public function onBytesAvailable(remedium:RemediumSystem):void {
			if (remedium.bytesAvailable() > 4) {
				remedium.produceByte(); // this should be initializer's byte
				var myID:int = remedium.produceInt();
				Log.debug("Read HostID: ", myID);
				remedium.initializeID(myID);
				remedium.setState(mainObjectReceivingState);
			}
		}
		
	}
}